import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        for (int i = 1; i < 999999; i++) {
            int count = 0;
            int tmp = i;
            while(tmp!=0){
                count++;
                tmp = tmp/10;
            }
            tmp = i;
            int sum = 0;
            while(tmp!=0){
                sum+=Math.pow(tmp%10,count);//pow是double类型所以要+=
                tmp/=10;
            }

            if(sum==i){
                System.out.println(i);
            }
        }
    }

    public static void main7(String[] args) {
        //辗转相除法求最大公约数
        int a = 24;
        int b = 18;
        int c = a%b;
        int d = a*b;
        while(c!=0){
            a=b;
            b=c;
            c=a%b;
        }
        System.out.println(b+"是最大公约数");
        System.out.println(d/b+"是最小公倍数");
    }

    public static void main6(String[] args) {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i+"*"+j+"="+i*j+" ");
            }
            System.out.println();
        }
    }

    public static void isPrime(int n) {
        int i = 2;
        for(;i<=Math.sqrt(n);i++) {
            if(n%i==0){
                System.out.println(n+"不是素数");
                break;
            }
        }
        if(i>Math.sqrt(n)){
            System.out.println(n+"是素数");
        }
    }
    public static void main5(String[] args) {
        for (int i = 1; i <= 100 ; i++) {
            isPrime(i);
        }
    }

    public static void main4(String[] args) {
        int n = 19;
        int i = 2;
        for (; i <= Math.sqrt(n); i++) {
            if(n%i==0){
                System.out.println("不是素数");
                break;
            }
        }
        if(i>Math.sqrt(n)){
            System.out.println("是素数");
        }
    }

    public static void main3(String[] args) {
        int n = 17;
        int i = 2;
        for (; i <= n/2 ; i++) {
            if(n%i==0){
                System.out.println("不是素数");
                break;
            }
        }
        if(i>n/2){
            System.out.println("是素数");
        }
    }

    public static void main2(String[] args) {
        int n = 7;
        int i = 2;
        for (; i < n; i++) {
            if(n%i==0){
                System.out.println("不是素数");
                break;
            }
        }
        //1.i==n   2.n%i==0
        if(i==n){
            System.out.println("是素数");
        }
    }

    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int age = scanner.nextInt();
        if(age<18){
            System.out.println("少年");
        }else if(age>=18&&age<28){
            System.out.println("青年");
        }else if(age>=29&&age<55){
            System.out.println("中年");
        }else {
            System.out.println("老年");
        }
    }

}
